package com.hardware.controller;

import com.hardware.common.Result;
import com.hardware.entity.Navigation;
import com.hardware.service.NavigationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.hardware.utils.RedisConstants.CACHE_NAVIGATION_KEY;

/**
 * 前台：首页导航栏
 */
@RestController
@RequestMapping("/navigation")
@Slf4j
public class NavigationController {

    @Autowired
    private NavigationService navigationService;

    /**
     * 导航列表
     * @return
     */
    @GetMapping("/list")
    @Cacheable(value = CACHE_NAVIGATION_KEY)
    public Result queryTypeList() {
        List<Navigation> navigations = navigationService
                .query().orderByAsc("sort").list();
        return Result.ok(navigations);
    }
}
